#include <iostream>
#include <string>
#include <vector>

using namespace std;

// 2730. 找到最长的半重复子字符串
// https://leetcode.cn/problems/find-the-longest-semi-repetitive-substring/description/

class Solution
{
public:
    int longestSemiRepetitiveSubstring(string s)
    {
        int left = 0;
        int n = s.size();
        int ans = 1;
        int common = 1;
        for (int i = 1; i < n; i++)
        {
            if (s[i] == s[i - 1])
            {
                common--;
            }
            while (common < 0)
            {
                left++;
                if (left != 0 && s[left] == s[left - 1])
                {
                    common++;
                    continue;
                }
            }
            ans = max(ans, i - left + 1);
        }
        return ans;
    }
};

int main()
{
    return 0;
}